package com.dyit.springcloud.hospital.doctor.controller;

import com.dyit.springcloud.hospital.common.dto.HttpResp;
import com.dyit.springcloud.hospital.doctor.service.IDoctorService;
import com.dyit.springcloud.hospital.domain.entity.Dept;
import com.dyit.springcloud.hospital.domain.entity.Doctor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@RestController
@RequestMapping("/api/docker")
public class DoctorController {

    @Autowired
    private IDoctorService ids;

    @GetMapping("/findAllDoctor")
    public HttpResp findAll(){
        return new HttpResp(
                200,
                "查询成功",
                ids.findAll(),
                LocalDateTime.now()
        );
    }

    @GetMapping("/findByDept")
    public HttpResp findByDept(@RequestBody Dept dept){
        return new HttpResp(
                200,
                "查询成功",
                ids.findDoctorsByDept(dept),
                LocalDateTime.now()
        );
    }

    @GetMapping("/findByName")
    public HttpResp findByName(@Param("name")String name){
        return new HttpResp(
                200,
                "查询成功",
                ids.findDoctorByName(name),
                LocalDateTime.now()
        );
    }

    @PostMapping("/insertDoctor")
    public HttpResp insert(@RequestBody Doctor doctor){
        ids.add(doctor);
        return new HttpResp(
                200,
                "添加成功",
                LocalDateTime.now()
        );
    }

    @DeleteMapping("/deleteDoctor")
    public HttpResp delete(@Param("id")int id){

        ids.deleteDoctorById(id);
        return new HttpResp(
                200,
                "删除成功",
                LocalDateTime.now()
        );
    }

    @PutMapping("/update")
    public HttpResp update(@RequestBody Doctor doctor){
        ids.update(doctor);
        return new HttpResp(
                200,
                "修改成功",
                LocalDateTime.now()
        );
    }

}
